# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  include AuthenticatedSystem
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
#  before_filter :ensure_temp_schedule

#  def ensure_temp_schedule
#
#    begin
#      Schedule.find(session[:scheduleId])
#      found = true
#    rescue Exception => e
#      schedule = Schedule.create!
#      session[:scheduleId] = schedule
#    end
#  end

  # When called, working_schedule finds the schedule id stored in the session
  # or creates new one when there is no such schedule.
  # Thus, working_schedule is NEVER nil.
  def working_schedule
    schedules = Schedule.find(:all, :conditions => {:id => session[:scheduleId]})
    schedules[0] = Schedule.create! if schedules.empty?
    session[:scheduleId] = schedules[0].id
    return schedules[0]
  end

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
end
